package com.ghost.alibabaghost.service.sys;

import com.ghost.alibabaghost.api.model.sys.SysUserRoleModel;
import com.ghost.alibabaghost.api.service.sys.SysUserRoleService;
import com.ghost.alibabaghost.dao.dataobject.sys.SysUserRoleDO;
import com.ghost.alibabaghost.dao.mapper.sys.SysUserRoleMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yaolisheng
 * @version 1.0
 * @date 2022/1/14 23:05
 */
@Service("sysUserRoleService")
public class SysUserRoleServuceImpl implements SysUserRoleService {

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Override
    public SysUserRoleModel queryRoleByUserId(Integer userId) {
        SysUserRoleDO sysUserRoleDO = sysUserRoleMapper.queryRoleByUserId(userId);
        SysUserRoleModel sysUserRoleModel = new SysUserRoleModel();
        BeanUtils.copyProperties(sysUserRoleDO, sysUserRoleModel);
        return sysUserRoleModel;
    }

    @Override
    public Integer insertUserRole(SysUserRoleModel sysUserRoleModel) {
        SysUserRoleDO sysUserRoleDO = new SysUserRoleDO();
        BeanUtils.copyProperties(sysUserRoleModel, sysUserRoleDO);
        Integer integer = sysUserRoleMapper.insertUserRole(sysUserRoleDO);
        return integer;
    }

    @Override
    public Integer updateByUserId(SysUserRoleModel sysUserRoleModel) {
        SysUserRoleDO sysUserRoleDO = new SysUserRoleDO();
        BeanUtils.copyProperties(sysUserRoleModel, sysUserRoleDO);
        Integer integer = sysUserRoleMapper.updateByUserId(sysUserRoleDO);
        return integer;
    }
}
